package me.wangqu.weiyouqu.domain;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import javax.persistence.*;
import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.Objects;

/**
 * A ViewPager.
 */
@Entity
@Table(name = "view_pager")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class ViewPager implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @NotNull
    @Pattern(regexp = "^[a-zA-z]+://[^\\s]*$")
    @Column(name = "img", nullable = false)
    private String img;

    @NotNull
    @Pattern(regexp = "^[a-zA-z]+://[^\\s]*$")
    @Column(name = "url", nullable = false)
    private String url;

    @NotNull
    @Column(name = "type", nullable = false)
    private Integer type;

    @Column(name = "title")
    private String title;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getImg() {
        return img;
    }

    public void setImg(String img) {
        this.img = img;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Integer getType() {
        return type;
    }

    public void setType(Integer type) {
        this.type = type;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        ViewPager viewPager = (ViewPager) o;
        if(viewPager.id == null || id == null) {
            return false;
        }
        return Objects.equals(id, viewPager.id);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return "ViewPager{" +
            "id=" + id +
            ", img='" + img + "'" +
            ", url='" + url + "'" +
            ", type='" + type + "'" +
            ", title='" + title + "'" +
            '}';
    }
}
